package com.example.question.dp.dp4;

/**
 * @Date 2023-07-29
 * @Author Jonathan
 */
public class Code06_718 {
    public static void main(String[] args) {

    }

    public int findLength(int[] nums1, int[] nums2) {
        int m = nums1.length;
        int n = nums2.length;
        int[][] dp = new int[m][n];
        int res = 0;
        for (int row = 0; row < m; row++) {
            if (nums1[row] == nums2[0]) {
                dp[row][0] = 1;
                res = 1;
            }
        }
        for (int col = 0; col < n; col++) {
            if (nums2[col] == nums1[0]) {
                dp[0][col] = 1;
                res = 1;
            }
        }
        for (int row = 1; row < m; row++) {
            for (int col = 1; col < n; col++) {
                if (nums1[row] == nums2[col]) {
                    dp[row][col] = dp[row - 1][col - 1] + 1;
                    res = Math.max(dp[row][col], res);
                }
            }
        }
        return res;
    }
}
